package cn.lh.controller;


import cn.lh.config.Resp;
import cn.lh.entity.req.OrderListReq;
import cn.lh.entity.req.OrderReq;
import cn.lh.entity.req.ProductReq;
import cn.lh.entity.vo.ProductVo;
import cn.lh.service.ProductService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 产品表 前端控制器
 * </p>
 *
 * @author linhong
 * @since 2025-04-14
 */
@Api(tags = "产品")
@Validated
@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController extends BaseController{

    @Resource
    private ProductService productService;



    @ApiOperation(value = "新增/修改产品", notes = "新增/修改产品")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @PostMapping("/createOrUpdate")
    public Resp<?> createOrUpdate(@RequestHeader String authorization, @RequestBody @Valid ProductReq req){
        productService.saveOrUpdate(req);
        return ok();
    }

    @ApiOperation(value = "获取产品列表", notes = "获取产品列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "productName", value = "产品名称",  paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "productTypeId", value = "产品类型id",  paramType = "query", dataType = "Integer")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @GetMapping("/getList")
    public Resp<List<ProductVo>> getList(@RequestHeader String authorization, String productName,Integer productTypeId){
        return ok(productService.getList(productName,productTypeId));
    }


}

